import { _decorator, Component, Node, RigidBody2D, v2, v3, Vec2 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('MainCamera')
export class MainCamera extends Component {

    @property({type:Node})
    private player:Node = null

    l:number = 0

    v:Vec2 = v2(0,0)



    start() {

    }

    update(deltaTime: number) {
        this.v = this.player.getComponent(RigidBody2D).linearVelocity
        this.l = this.player.position.x - this.node.position.x

        if(this.l>10){
            // if(this.l<100+this.p){
            //     this.node.getComponent(RigidBody2D).linearVelocity = v2(this.v.x*this.l/100,0)
            //     return
            // }
            this.node.getComponent(RigidBody2D).linearVelocity = v2(this.v.x*1.1,0)
        }else if(this.l<-10){
            // if(this.l>-100+this.p){
            //     this.node.getComponent(RigidBody2D).linearVelocity = v2(this.v.x*this.l/100,0)
            //     return
            // }
            this.node.getComponent(RigidBody2D).linearVelocity = v2(this.v.x*0.9,0)
        }else(
            this.node.getComponent(RigidBody2D).linearVelocity = v2(this.v.x,0)
        )
        // this.node.setPosition(v3(this.player.position.x,this.node.position.y,this.node.position.z))
        
    }
}


